<?php

	// TITLE: Friends_of_habitat AUTO MODEL
	// FILE: scaffolding/model/friends_of_habitat.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createFriendsOfHabitat = function($con, $friendsOfHabitat) {
		$sql = 'INSERT INTO friends_of_habitat (event_id, person_id) VALUES (';
		$sql .= $friends_of_habitat->getEventId() . ', ';
		$sql .= $friends_of_habitat->getPersonId() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readFriendsOfHabitat = function($con, $id) {
		$sql = 'SELECT * FROM friends_of_habitat WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$friendsOfHabitat = new FriendsOfHabitat();
			$friendsOfHabitat->setEventId($dbio->select($readEvent(result[0])));
			$friendsOfHabitat->setPersonId($dbio->select($readPerson(result[1])));
		} else {
			$friendsOfHabitat = false;
		}
		return $friendsOfHabitat;
	};

	$updateFriendsOfHabitat = function($con, $friendsOfHabitat) {
		$sql = 'UPDATE friends_of_habitat SET ';
		$sql .= 'event_id = ' . $friends_of_habitat->getEventId() . ', ';
		$sql .= 'person_id = ' . $friends_of_habitat->getPersonId() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteFriendsOfHabitat = function($con, $id) {
		$sql = 'DELETE FROM friends_of_habitat WHERE event_id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listFriendsOfHabitat = function($con) {
		$sql = 'SELECT * FROM friends_of_habitat';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$friendsOfHabitats = array();
			while ($result = mysqli_fetch_array($results)) {
				$friendsOfHabitat = new FriendsOfHabitat();
				$friendsOfHabitat->setEventId($dbio->select($readEvent(result[0])));
				$friendsOfHabitat->setPersonId($dbio->select($readPerson(result[1])));
				$friendsOfHabitats[] = friendsOfHabitat;
			}// end while
		} else {
			$friendsOfHabitats = false;
		}
		return $friendsOfHabitats;
	};

